package com.sangeng.controller;

import com.sangeng.domain.LoginRequest;
import com.sangeng.domain.ResponseResult;
import com.sangeng.entity.User;
import com.sangeng.service.LoginServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: xujiabing
 * @date: 2024-09-13 18:20
 * @description 登录接口
 */
@RestController
public class LoginController {

    @Autowired
    private LoginServcie loginServcie;

    /**
     * 用户登录接口
     * @param user
     * @return
     */
    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody User user){
        return loginServcie.login(user);
    }

    /**
     * 用户登录接口-带有验证码
     * @param user
     * @return
     */
    @PostMapping("/user/loginWithCaptcha")
    public ResponseResult loginWithCaptcha(@RequestBody @Validated LoginRequest loginRequest){
        return loginServcie.loginWithCaptcha(loginRequest);
    }

    /**
     * 退出登录
     * @return
     */
    @PostMapping("/user/logout")
    public ResponseResult logout() {
        return loginServcie.logout();
    }
}
